import java.io.*;
import java.net.*;
import java.text.SimpleDateFormat;
import java.util.*;

class EnvoieUneRequete extends Thread {
	String 	site;
	String 	page;
	int 		port;
	EnvoieUneRequete(String s, String pa, int po) {
		site = s; page = pa; port = po;
	}
	public void run () {
		try {
			Socket		socket = new Socket(site, port);
			InputStream		socketInputStream = socket.getInputStream();
			byte[] 		dataRecue = new byte[8096];
			String		chaineRecue;
			OutputStream	socketOutputStream = socket.getOutputStream();
			String		requete = "GET " + page + " HTTP/1.0\n\n";
	
			socketOutputStream.write(requete.getBytes());
			int taille = socketInputStream.read(dataRecue);
			while ( taille != -1) {
//				chaineRecue = new String(dataRecue,0,taille);
//				System.out.println(chaineRecue);
				taille = socketInputStream.read(dataRecue);
			}
			socket.close();
		}
		catch (Exception e) {}
	}
}

public class ClientHTTP {

	public static void main(String[] args) throws Exception {
		String	site = "localhost";
		String	page = args.length > 1 ? args[0] : "/index.html";
		int	port = 150;
		int	nombreDeThreads = args.length > 2 ? Integer.parseInt(args[1]) : 50000;

                Date start = new Date();
		for (int i=0; i<nombreDeThreads; i++) {
			EnvoieUneRequete thread = new EnvoieUneRequete(site, page, port);
			thread.start();
		}
                Date end = new Date();
                long time = (end.getTime()/1000) - (start.getTime()/1000);
                SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
                
                System.out.println("----");
                System.out.println("Start Date: " + ft.format(start));
                System.out.println("End Date: " + ft.format(end));
                System.out.println("Time Process: " + time + " seconds");
                System.out.println("----");
	}
}
